package com.cnu.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cnu.common.Result;
import com.cnu.sys.entity.Irregular;
import com.cnu.sys.service.IIrregularService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lmq
 * @since 2023-09-06
 */
@RestController
@RequestMapping("/irregular")
public class IrregularController {

    @Autowired
    private IIrregularService irregularService;

    @GetMapping("/getList")
    public Result<Map<String, Object>> getList() {
        List<Map<String, Object>> rows = irregularService.getList();
        Map<String, Object> res = new HashMap<>();
        res.put("rows", rows);
        return Result.success(res, "查询成功");
    }

    @GetMapping("/getPage")
    public Result<Map<String, Object>> selectList(@RequestParam(value = "pageNo") Long pageNo,
                                                  @RequestParam(value = "pageSize") Long pageSize) {
        Page<Irregular> page = new Page<>(pageNo, pageSize);
        irregularService.page(page);

        Map<String, Object> data = new HashMap<>();
        data.put("total", page.getTotal());
        data.put("rows", page.getRecords());

        return Result.success(data);
    }
}
